package Tables;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
public class DriverRouteNameTableInterface extends JPanel implements ActionListener  {
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    JButton driverRouteAddButton=new JButton("Yeni");
    
    public DriverRouteNameTableInterface() {
    	
    	super(new GridBagLayout());
 
        String[] columnNames = {"Soför",
                                "Gün",
                                "Rut Name"};
 
        Object[][] data = {
        {"Hasan", "P.tesi","H_Pt"},
        {"Hasan", "Sal�","H_Sa"},
        {"Hasan", "�r�.","H_Ca"},
        {"Hasan", "Pr�","H_Pr"},
        {"Hasan", "Cuma","H_Cu"},
        {"Hasan", "C.tesi","H_Ct"},
        {"Hasan", "Pazar","H_Pa"}
        };

        for(int i=0;i<columnNames.length;i++)
        	model.addColumn(columnNames[i]);	//add columns
        
        table.setPreferredScrollableViewportSize(new Dimension(920, 600));
        table.setFillsViewportHeight(true);
        for(int i=0;i<data.length;i++)
        	model.addRow(data[i]);
        
        TableColumn column = new TableColumn();
        for (int i = 0; i < columnNames.length; i++) {
            column = table.getColumnModel().getColumn(i);
            column.setPreferredWidth(45);
            
        }
      
        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);
      //Add the scroll pane to this panel.
        add(scrollPane);
        
        
        driverRouteAddButton.addActionListener(this);
        addItem(driverRouteAddButton,0,1,1,1,GridBagConstraints.CENTER);//call the addItem method and add in panel
        
        
        
       
       
    }
    
    /**
     * This method Add new row to the table
     */
    private void addTableByRow(Object[] yeni){
    	model.addRow(yeni);
   
    }
    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    public void createAndShowGUI() {
        //Create and set up the window.
        JFrame myframe = new JFrame("��f�r RutName Tablosu");
        myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        //Create and set up the content pane.
        DriverRouteNameTableInterface newContentPane = new DriverRouteNameTableInterface();
        newContentPane.setOpaque(true); //content panes must be opaque
        myframe.setContentPane(newContentPane);
 
        //Display the window.
        TableGetXY tmp=new TableGetXY();
        myframe.setLocation(tmp.upperLeftX,tmp.upperLeftY);
        myframe.pack();
        myframe.setVisible(true);
    }

    /**
     *This method is good to use GridBagLayout simple
     * 
     */
    private void addItem(JComponent c, int x, int y, int width, int height, int align) {
        GridBagConstraints gc = new GridBagConstraints();
        gc.gridx = x;
        gc.gridy = y;
        gc.gridwidth = width;
        gc.gridheight = height;
        gc.weightx = 100.0;
        gc.weighty = 100.0;
        gc.insets = new Insets(5, 5, 5, 5);
        gc.anchor = align;
        gc.fill = GridBagConstraints.NONE;
        add(c, gc);
      }
	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}


